﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace version1
{
    public class Sprite2D
    {
        public Texture2D[] _sprite;
        private Vector2 _size=new Vector2(0,0);

        public Vector2 Size
        {
            get { return _size; }
            set { _size = value; }
        }
        public Texture2D[] Sprite
        {
            get { return _sprite; }
            set
            {
                _sprite = value;
                _nsprite = _sprite.Length;
                _isprite = 0;             
            }

        }
        public int _nsprite;

        public int Nsprite
        {
            get { return _nsprite; }
            set { _nsprite = value; }
        }
        public int _isprite;

        public int Isprite
        {
            get { return _isprite; }
            set { _isprite = value; }
        }
        public Vector2 _position;

        public Vector2 Position
        {
            get { return _position; }
            set { _position = value; }
        }

        private float delay = 40.0f;

        public float Delay
        {
            get { return delay; }
            set { delay = value; }
        }
        public Sprite2D(Texture2D[] texture, Vector2 position)
        {
            Sprite = texture;
            Position = position;
        }
        public void Update(GameTime gametime)
        {
            int time = (int)(gametime.TotalGameTime.Milliseconds / delay);
            _isprite = ( time) % _nsprite; 
        }
      
        public void Draw(SpriteBatch spritebatch, GameTime gameTime)
        {
            //spritebatch.Draw(_sprite[_isprite], _position, Color.White);
            Rectangle rec = new Rectangle(); 
           //Thay doi kich thuoc hinh
            if(_size.X==0)
                rec=new Rectangle((int)_position.X, (int)_position.Y, _sprite[_isprite].Width, _sprite[_isprite].Height);
            else
                rec = new Rectangle((int)_position.X, (int)_position.Y, (int)_size.X, (int)_size.Y);
            spritebatch.Draw(_sprite[_isprite],rec, Color.White);
        }
    }
}
